package com.example.lenovo.dynamicproxy_lxy.proxy;

import com.orhanobut.logger.Logger;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * Created by lenovo on 2017/11/8.
 */

public class DynamicProxy implements InvocationHandler{

    private Object target;
    private long mStime;

    public DynamicProxy(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object o, Method method, Object[] args) throws Throwable {
        before();
        Object result=method.invoke(target,args);
        after();
        return result;
    }


    private void before() {
        mStime = System.currentTimeMillis();
        Logger.d("执行任务开始咯------");
    }

    private void after() {
        long ftime = System.currentTimeMillis();
        Logger.d("执行任务耗时"+(ftime - mStime)+"毫秒");
    }

}
